A database is a collection of logically related data arranged in a predetermined format, such as in tables that contain rows and columns. To access the content of a table in the database, queries according to a standard database query language (such as the Structured Query Language or SQL) are submitted to the database. A query can be issued to insert new entries into a table of a database (such as to insert a row into the table), modify the content of the table, or to delete entries from the table.
Examples of SQL statements include INSERT, SELECT, UPDATE, and DELETE. The SELECT statement is used to retrieve information from a database and to organize information for presentation to a user or to an application program. A SELECT statement can include a GROUP BY clause, which specifies a grouping function to group the output results according to one or more attributes specified in the GROUP BY clause.
Starting with SQL-99 (also referred to as SQL3), further types of group-by operations have been defined, including group-by with grouping sets, group-by with rollup, and group-by with cube. These are all referred to as “cube-based” grouping or group-by operations. The following is an example of a SELECT statement with a GROUP BY CUBE clause (to specify a cube operation):                SELECT C1, C2, SUM(C3) AS “SUM”        FROM TABLE A        GROUP BY CUBE (C1, C2);        
The result produced by a database system in response to such a SELECT statement is as follows:
C1C2SUMA11.0A22.3ANULL3.3B18.0BNULL8.0NULL19.0NULL22.3NULLNULL11.3
In addition to the same groups returned by the ordinary GROUP BY clause, the GROUP BY CUBE clause further obtains a group of each group: the group of C1 having the “A” value (with C2 having a NULL or don't care value such that all rows of Table A where C1 has the “A” value are grouped); the group of C1 having the “B” value (with C2 having a NULL or don't care value such that all rows where C1 has the “B” value are grouped); the group of C2 having the “1” value (with C1 having a NULL or don't care value); the group of C2 having the “2” value (with C1 having a NULL or don't care value); and the group where both C1 and C2 have NULL values (in effect a grouping of all rows of Table A). In effect, a group-by cube operation involves grouping on all possible grouping sets. In the above example, given a cube function on attributes C1 and C2, the following are the possible grouping sets: {C1, C2}, {C1}, {C2}, and {All}.
Partial cube operations can be performed in response to query with GROUP BY ROLLUP or GROUP BY GROUPING SETS clauses. A partial cube operation involves group-bys on less than all possible grouping sets of a cube operation.
To enhance response times of cube-based operations, views that store results of cube-based operations are maintained. A view is a derived relation formed by performing a function (such as a cube-based operation) on one or more base relations. A materialized view is a pre-computed view that is actually stored by the database system. A database system can retrieve content of such a materialized view to increase the response time for computing a cube-based query.
An issue associated with storing a view containing results of cube-based operations is that maintenance of the view can be relatively expensive in terms of consumption of database system resources. Maintenance of a view refers to modifying the content of the view in response to changes (row insert, row delete, row update) in underlying base table(s). Note that a cube-based query is applied on one or plural base tables. Changes in such base table(s) will cause group-by results stored in the materialized view to change. Because a view may contain group-by results for a large number of grouping sets, the re-calculation of such group-by results in response to modifications of base table(s) can be computationally intensive if performed inefficiently.